package hz.mobileproject.pda.callroll.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import hz.mobileproject.pda.R;
import hz.mobileproject.pda.entity.response.Response_loadPrisonerList;
import hz.mobileproject.pda.callroll.manger.CallRollByFaceDataMgr;
import hz.mobileproject.pda.callroll.manger.PhotoUpdateMgr;
import hz.mobileproject.pda.utils.FileUtils;

/**
 * Created by hasee on 2017/11/2.
 */

public class CallRollByFaceListAdapter extends BaseAdapter {

    private List<Response_loadPrisonerList> mList;

    private LayoutInflater mInflater;

    private Context mContext;

    public CallRollByFaceListAdapter(Context context, List<Response_loadPrisonerList> list){
        mContext = context;
        mList = list;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mList == null ? 0 : mList.size();
    }

    @Override
    public Object getItem(int i) {
        return mList == null ? null : mList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        ViewHolder vh;
        if(view == null){
            vh = new ViewHolder();
            view = mInflater.inflate(R.layout.call_roll_face_list_item, null);
            vh.tvName = (TextView) view.findViewById(R.id.tv_call_roll_face_name);
            vh.tvId = (TextView) view.findViewById(R.id.tv_call_roll_face_id);
            vh.tvDept = (TextView) view.findViewById(R.id.tv_call_roll_face_dept);
            vh.tvStatus = (TextView) view.findViewById(R.id.tv_call_roll_face_status);
            vh.ivPhoto = (ImageView) view.findViewById(R.id.iv_call_roll_face_photo) ;
            view.setTag(vh);
        }else{
            vh = (ViewHolder) view.getTag();
        }

        vh.tvName.setText(mList.get(i).getPrisoner_name());
        vh.tvId.setText(mList.get(i).getPrisoner_id());
        vh.tvDept.setText(mList.get(i).getDepartment_name());
        String path = FileUtils.getAppPath(PhotoUpdateMgr.PIC_PATH_NAME)
                + mList.get(i).getPrisoner_id() + ".jpg";
        Glide.with(mContext).load(path).centerCrop().into(vh.ivPhoto);
        switch (mList.get(i).callRollStatus){
            case 0:
                vh.tvStatus.setText("未点");
                break;
            case 1:
                vh.tvStatus.setText("上传中");
                break;
            case 2:
                vh.tvStatus.setText("上传成功");
                break;
            case 3:
                vh.tvStatus.setText("上传失败");
                break;
            default:
                break;
        }

        return view;
    }

    /**
     * 针对列表排序
     * 未点，失败，上传中，已上传
     */
    public void refreshAdapterBySort(){
        CallRollByFaceDataMgr.getInstance().sortAllPrisonerList();
        notifyDataSetChanged();
    }

    static class ViewHolder{
        TextView tvName;
        TextView tvId;
        TextView tvDept;
        TextView tvStatus;
        ImageView ivPhoto;
    }

}

